package com.lianzhihui.romeex.widget.dialog;

import android.content.Context;
import android.view.View;
import android.widget.EditText;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ToastUtils;
import com.lianzhihui.romeex.MyApplication;
import com.lianzhihui.romeex.R;
import com.lianzhihui.romeex.ui.base.BaseDialog;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @ProjectName: romeex
 * @Package: com.lianzhihui.romeex.ui.me.dialog
 * @ClassName: UpDateVersionDialog
 * @Description: 填写邀请码弹窗
 * @Author: zhanghong
 * @CreateDate: 2020/11/3 10:40
 * @UpdateUser: 更新者：
 * @UpdateDate: 2020/11/3 10:40
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class InputInvCodeDialog extends BaseDialog {

    Callback call;
    @BindView(R.id.et_input)
    EditText etInput;


    public InputInvCodeDialog(@NonNull Context context) {
        super(context);
    }

    public InputInvCodeDialog(Context context, int style) {
        super(context, style);
    }

    public void setCallback(Callback call) {
        this.call = call;
    }

    public void setInvCode(String code) {
        if (!code.isEmpty()) {
            etInput.setText(code);
        }
    }

    @Override
    public void setCancelable(boolean flag) {
        super.setCancelable(flag);
    }


    @Override
    public void show() {
        super.show();
    }

    @Override
    public void dismiss() {
        this.call = null;
        super.dismiss();
    }

    @Override
    protected int provideViewId() {
        return R.layout.dialog_input_inv_code;
    }

    @Override
    protected void initView() {
    }


    @OnClick({R.id.iv_scan, R.id.tv_confirm})
    public void OnClick(View v) {
        switch (v.getId()) {
            case R.id.iv_scan:
                if (call != null) {
                    call.scan();
                }
                break;
            case R.id.tv_confirm:
                if (etInput.getText().toString().isEmpty()) {
                    ToastUtils.showShort(MyApplication.mContext.getResources().getString(R.string.text_inv_isempty));
                    return;
                }
                if (call != null) {
                    call.confirm(etInput.getText().toString().trim());
                }
                break;
            default:
                break;
        }
    }


    public interface Callback {
        void confirm(String s);

        void scan();
    }


}
